home *** CD-ROM | disk | FTP | other *** search
/ PC Users 1998 March / Pc Users extra 6.iso / pshare95 / prog / formula1 / vcform1.z / ssmdi.bas < prev    next >
Encoding:
BASIC Source File  |  1997-09-26  |  25.3 KB  |  786 lines

  1. Attribute VB_Name = "SSMDI1"
  2. Option Explicit
  3.  
  4. '' This variable is used to name the worksheets in each
  5. '' child window.
  6. Global gNewSSCount As Integer
  7.  
  8. '' These are used for the Format Painter command
  9. Global FormatPainterFlag As Integer
  10. Global FmtPntStartRow As Integer
  11. Global FmtPntEndRow As Integer
  12. Global FmtPntStartCol As Integer
  13. Global FmtPntEndCol As Integer
  14.  
  15. '' Used for reading metafiles
  16. Type Rect
  17.     bbLeft As Integer
  18.     bbTop As Integer
  19.     bbRight As Integer
  20.     bbBottom As Integer
  21. End Type
  22.  
  23. Type APMFILEHEADER
  24.     key As Long
  25.     hmf As Integer
  26.     bbox As Rect
  27.     inch As Integer
  28.     reserved As Long
  29.     checksum As Integer
  30. End Type
  31.  
  32. Sub AddDecimalPlace(AddingDigits As Integer)
  33.  
  34.     Dim TheFormat As String, TheNewFormat As String, TheChar As String
  35.     Dim TheFormatLen As Integer, FromPointer As Integer
  36.     Dim DecimalPointFound As Integer, ScientificFound As Integer
  37.     Dim ss As Object
  38.  
  39.  
  40.     ' This routine parses the format strings associated with the selected cell
  41.     ' and either adds or subtracts a decimal place depending on the setting of
  42.     ' AddingDigits.  It is not internationalized and will only work with
  43.     ' American settings (i.e. period for decimal, comma for thousands).
  44.     
  45.     ' If no active sheet then don't do anything
  46.     If Not (MainFrame.ActiveForm Is Nothing) Then
  47.  
  48.         ' Save the object into a variable to save on typing.
  49.         Set ss = MainFrame.ActiveForm.ss
  50.  
  51.         ' Get the format for the active cell.
  52.         TheFormat = ss.NumberFormat
  53.         
  54.         ' Don't handle the percentage formats
  55.         If TheFormat = "# ?/?" Or TheFormat = "# ??/??" Then
  56.             Beep
  57.             ss.SetFocus
  58.             Exit Sub
  59.         End If
  60.         
  61.         ' FromPointer is moved through the original string one character at a time.  Format
  62.         ' characters are copied to TheNewFormat and special cases handled individually.
  63.         
  64.         TheFormatLen = Len(TheFormat)
  65.         FromPointer = 1
  66.         
  67.         While FromPointer <= TheFormatLen
  68.         
  69.             TheChar = Mid$(TheFormat, FromPointer, 1)
  70.  
  71.             ' Process numbers
  72.             If TheChar = "0" Or TheChar = "#" Then
  73.                 
  74.                 ' If adding digits then find the decimal or add one if there is none
  75.                 If AddingDigits = True Then
  76.                     DecimalPointFound = False
  77.                     ScientificFound = False
  78.                     Do While FromPointer <= TheFormatLen
  79.                         TheChar = Mid$(TheFormat, FromPointer, 1)
  80.                         If TheChar = "." Then DecimalPointFound = True
  81.                         If TheChar = "E" Or TheChar = "e" Then ScientificFound = True
  82.                         If TheChar <> "0" And TheChar <> "#" And TheChar <> "." And TheChar <> "," Then Exit Do
  83.                         TheNewFormat = TheNewFormat + TheChar
  84.                         FromPointer = FromPointer + 1
  85.                     Loop
  86.     
  87.                     ' Add the decimal point if it didn't have one before
  88.                     If Not DecimalPointFound Then
  89.                         TheNewFormat = TheNewFormat + "."
  90.                     End If
  91.     
  92.                     ' Now add the new decimal place and we're done
  93.                     TheNewFormat = TheNewFormat + "0"
  94.                 
  95.                 ' Removing Digits
  96.                 Else
  97.                     DecimalPointFound = 0
  98.                     ScientificFound = False
  99.                     Do While FromPointer <= TheFormatLen
  100.                         TheChar = Mid$(TheFormat, FromPointer, 1)
  101.                         If TheChar = "." Then DecimalPointFound = Len(TheNewFormat) + 1
  102.                         If TheChar = "E" Or TheChar = "e" Then ScientificFound = True
  103.                         If TheChar <> "0" And TheChar <> "#" And TheChar <> "." And TheChar <> "," Then Exit Do
  104.                         TheNewFormat = TheNewFormat + TheChar
  105.                         FromPointer = FromPointer + 1
  106.                     Loop
  107.  
  108.                     If DecimalPointFound = 0 Then
  109.                         Beep
  110.                     Else
  111.                         ' Remove the rightmost character (either a 0 or a ".")
  112.                         TheNewFormat = Left$(TheNewFormat, Len(TheNewFormat) - 1)
  113.                         ' If there's only a decimal point left at the end, remove it
  114.                         If Right$(TheNewFormat, 1) = "." Then
  115.                             TheNewFormat = Left$(TheNewFormat, Len(TheNewFormat) - 1)
  116.                         End If
  117.                     End If
  118.                 End If
  119.                 
  120.                 ' If we weren't at the end of the string, add the last character on
  121.                 If FromPointer <= TheFormatLen Then
  122.                     TheNewFormat = TheNewFormat + TheChar
  123.                 End If
  124.                 
  125.                 ' If scienticic notation, then skip the rest of this number format
  126.                 If ScientificFound Then
  127.                     Do While FromPointer <= TheFormatLen
  128.                         FromPointer = FromPointer + 1
  129.                         TheChar = Mid$(TheFormat, FromPointer, 1)
  130.                         TheNewFormat = TheNewFormat + TheChar
  131.                         If TheChar <> "0" And TheChar <> "+" And TheChar <> "-" Then Exit Do
  132.                     Loop
  133.                 End If
  134.                 
  135.             ' Skip everything in the boxes (Colors or Conditionals)
  136.             ElseIf TheChar = "[" Then
  137.                 Do While FromPointer <= TheFormatLen
  138.                     TheChar = Mid$(TheFormat, FromPointer, 1)
  139.                     TheNewFormat = TheNewFormat + TheChar
  140.                     If TheChar = "]" Then Exit Do
  141.                     FromPointer = FromPointer + 1
  142.                 Loop
  143.             
  144.             'Skip everything in quotes
  145.             ElseIf TheChar = Chr$(34) Then
  146.                 Do While FromPointer <= TheFormatLen
  147.                     TheChar = Mid$(TheFormat, FromPointer, 1)
  148.                     TheNewFormat = TheNewFormat + TheChar
  149.                     If TheChar = Chr$(34) Then Exit Do
  150.                     FromPointer = FromPointer + 1
  151.                 Loop
  152.             
  153.             ' Copy the "\" or "_" and the next character without change
  154.             ElseIf TheChar = "_" Or TheChar = "\" Then
  155.                 TheNewFormat = TheNewFormat + TheChar
  156.                 FromPointer = FromPointer + 1
  157.                 TheChar = Mid$(TheFormat, FromPointer, 1)
  158.                 TheNewFormat = TheNewFormat + TheChar
  159.             
  160.             ' All other characters are copied across without changing
  161.             Else
  162.                 TheNewFormat = TheNewFormat + TheChar
  163.             End If
  164.  
  165.             FromPointer = FromPointer + 1
  166.         Wend
  167.         
  168.         
  169.         ' Handle General format separately
  170.         If TheNewFormat = "General" Then
  171.             If AddingDigits = True Then
  172.                 TheNewFormat = "0.0"
  173.             Else
  174.                 Beep
  175.             End If
  176.         End If
  177.         
  178.         ' Set the decimal places for each cell.
  179.         ss.NumberFormat = TheNewFormat
  180.  
  181.     End If
  182.  
  183.     ss.SetFocus
  184.  
  185. End Sub
  186.  
  187. Sub C_AutoSum()
  188.  
  189.    Dim OldRow1%, OldRow2%, OldCol1%, OldCol2%, OldRow%, OldCol%
  190.    Dim TheRow%, TheCol%, TheType%
  191.    Dim TheFormula$
  192.  
  193.    '' This function partly emulates the function of Excel's AutoSum command.  It automatically
  194.    '' creates a formula that sums the cells above it.  If a range is selected then it will
  195.    '' automatically fill the range with the new sum formula.
  196.  
  197.    '' Unlike Excel, it only sums cells above it (and not to the left).  This extension could
  198.    '' easily be added using the simple framework below.
  199.     
  200.    If SSIsActiveForm() Then  ' Make sure there is an active worksheet
  201.         
  202.       '' Save the original range information for later
  203.       OldRow = MainFrame.ActiveForm.ss.Row            '' Current Row
  204.       OldCol = MainFrame.ActiveForm.ss.Col            '' Current Column
  205.       OldRow1 = MainFrame.ActiveForm.ss.SelStartRow   '' Current Selection
  206.       OldRow2 = MainFrame.ActiveForm.ss.SelEndRow     '' "
  207.       OldCol1 = MainFrame.ActiveForm.ss.SelStartCol   '' "
  208.       OldCol2 = MainFrame.ActiveForm.ss.SelEndCol     '' "
  209.         
  210.       TheRow = OldRow ' Get the row and colum of the current cell
  211.       TheCol = OldCol ' so we can look above it for a range to sum
  212.         
  213.       If TheRow = 1 Then  ' Can't do it if this is row 1
  214.          Beep
  215.          Exit Sub
  216.         
  217.       Else
  218.             
  219.          '' Look above this cell for numbers or formulas returning numbers.  Ignore all blank cells.
  220.             
  221.          TheRow = TheRow - 1
  222.          Do
  223.             TheType = MainFrame.ActiveForm.ss.TypeRC(TheRow, TheCol)
  224.             If Abs(TheType) = 1 Then  ' 1 (Number) or -1 (Number Formula) are valid cell types to sum
  225.                Exit Do
  226.             ElseIf Abs(TheType) > 1 Then ' Not a valid type (text, error, logical) so return error
  227.                Beep
  228.                Exit Sub
  229.             End If
  230.                 
  231.             TheRow = TheRow - 1
  232.                 
  233.             If TheRow < 1 Then ' If we made it to the top and have not found a number cell then error
  234.                Beep
  235.                Exit Sub
  236.             End If
  237.          Loop
  238.             
  239.          '' We found the first number cell, now keep moving up until a non-numeric cell is found
  240.          Do While TheRow > 0
  241.             TheType = MainFrame.ActiveForm.ss.TypeRC(TheRow, TheCol)
  242.             If Abs(TheType) <> 1 Then  ' 1 (Number) or -1 (Number Formula) are valid cell types to sum
  243.                Exit Do
  244.             End If
  245.                TheRow = TheRow - 1
  246.          Loop
  247.             
  248.          '' Create a new selection based on the range we just found
  249.          MainFrame.ActiveForm.ss.SelStartRow = TheRow + 1
  250.          MainFrame.ActiveForm.ss.SelEndRow = OldRow - 1
  251.          MainFrame.ActiveForm.ss.SelStartCol = OldCol1
  252.          MainFrame.ActiveForm.ss.SelEndCol = OldCol1
  253.             
  254.          '' The Selection property contains a string representation of the selection
  255.          TheFormula = "Sum(" + MainFrame.ActiveForm.ss.Selection + ")"
  256.             
  257.          '' Put the new sum into the first cell in the range
  258.          MainFrame.ActiveForm.ss.Row = OldRow1
  259.          MainFrame.ActiveForm.ss.Col = OldCol1
  260.          MainFrame.ActiveForm.ss.Formula = TheFormula
  261.         
  262.          '' Put everything back the way we started
  263.          MainFrame.ActiveForm.ss.Row = OldRow
  264.          MainFrame.ActiveForm.ss.Col = OldCol
  265.          MainFrame.ActiveForm.ss.SelStartRow = OldRow1
  266.          MainFrame.ActiveForm.ss.SelEndRow = OldRow2
  267.          MainFrame.ActiveForm.ss.SelStartCol = OldCol1
  268.          MainFrame.ActiveForm.ss.SelEndCol = OldCol2
  269.  
  270.          '' Copy the formula right to fill the range (the range may only be one cell)
  271.          '' Formula cell references will adjust automatically
  272.          MainFrame.ActiveForm.ss.EditCopyRight
  273.         
  274.       End If
  275.    End If
  276.  
  277. End Sub
  278.  
  279. Sub C_Clear()
  280.  
  281.    '' Clear the current selection(s)
  282.    On Error Resume Next
  283.    If SSIsActiveForm() Then
  284.       MainFrame.ActiveForm.ss.EditClear (F1ClearAll)
  285.    End If
  286.  
  287. End Sub
  288.  
  289. Sub C_Copy()
  290.  
  291.    If SSIsActiveForm() Then
  292.       MainFrame.ActiveForm.ss.EditCopy
  293.    End If
  294.  
  295. End Sub
  296.  
  297. Sub C_Cut()
  298.  
  299.    If SSIsActiveForm() Then
  300.       MainFrame.ActiveForm.ss.EditCut
  301.    End If
  302.  
  303. End Sub
  304.  
  305. Sub C_New()
  306.    
  307.    On Error GoTo CantCreateNewOne
  308.    Dim ss As New frmMDIChild       '' Create a new worksheet and
  309.    ss.Visible = True                '' make it visible
  310.    Exit Sub
  311.  
  312. CantCreateNewOne:
  313.    MsgBox "Unable to create new worksheet."
  314.  
  315. End Sub
  316.  
  317. Sub C_Paste()
  318.  
  319.    If SSIsActiveForm() Then
  320.       MainFrame.ActiveForm.ss.EditPaste
  321.    End If
  322.  
  323. End Sub
  324.  
  325. Sub C_Save()
  326.     Dim response%
  327.    If SSIsActiveForm() Then
  328.       If Left$(MainFrame.ActiveForm.ss.TableName, 5) = "F1Book" Then
  329.          response = SSMDISaveAsFile
  330.       Else
  331.          On Error GoTo CantSave
  332.          MainFrame.ActiveForm.ss.Write MainFrame.ActiveForm.ss.TableName, MainFrame.ActiveForm.ss.Tag
  333.          Exit Sub
  334. CantSave:
  335.          MsgBox "Unable to save " & MainFrame.ActiveForm.ss.TableName
  336.          Exit Sub
  337.       End If
  338.    End If
  339.  
  340. End Sub
  341.  
  342. Sub C_Sort(ascending%)
  343.  
  344.    Dim Srow1%, Srow2%, Scol1%, Scol2%, key1%, key2%, Key3%
  345.  
  346.    If SSIsActiveForm() Then
  347.       Srow1 = MainFrame.ActiveForm.ss.SelStartRow
  348.       Srow2 = MainFrame.ActiveForm.ss.SelEndRow
  349.       Scol1 = MainFrame.ActiveForm.ss.SelStartCol
  350.       Scol2 = MainFrame.ActiveForm.ss.SelEndCol
  351.       key1 = 1
  352.       key2 = 1
  353.       Key3 = 1
  354.       If Scol2 - Scol1 > 0 Then key2 = 2
  355.       If Scol2 - Scol1 > 1 Then Key3 = 3
  356.         
  357.       If Not ascending Then
  358.          key1 = -key1
  359.          key2 = -key2
  360.          Key3 = -Key3
  361.       End If
  362.       MainFrame.ActiveForm.ss.Sort3 Srow1, Scol1, Srow2, Scol2, True, key1, key2, Key3
  363.    End If
  364.  
  365. End Sub
  366.  
  367. Sub Paint_Reference()
  368.  
  369.    'MainFrame.RCLabel = MainFrame.ActiveForm.SS.Selection
  370.  
  371. End Sub
  372.  
  373. Sub SetBorderStyle(TheStyle As Integer)
  374.  
  375.     Dim nOutline%, nLeft%, nRight%, nTop%, nBottom%, nShade%
  376.     Dim crOutline&, crLeft&, crRight&, crTop&, crBottom&
  377.     Dim ss As Object
  378.     
  379.     ' This routine sets the border style of the current selection.  The border
  380.     ' style is passed in through TheStyle.
  381.     
  382.     ' Get a handle to the current spreadsheet to save typing.
  383.     Set ss = MainFrame.ActiveForm.ss
  384.     
  385.     ' Set all sides to "Don't Change" (-1 means don't change it)
  386.     nOutline = -1
  387.     nLeft = -1
  388.     nRight = -1
  389.     nTop = -1
  390.     nBottom = -1
  391.     nShade = -1
  392.     
  393.     ' Set the color of the new borders to Black
  394.     crOutline = 0
  395.     crTop = 0
  396.     crBottom = 0
  397.     crLeft = 0
  398.     crRight = 0
  399.     
  400.     ' Set the outline for selected cells
  401.     Select Case TheStyle
  402.     
  403.         Case 0 ' None
  404.             nOutline = 0
  405.             nLeft = 0
  406.             nRight = 0
  407.             nTop = 0
  408.             nBottom = 0
  409.             
  410.         Case 1 ' Bottom
  411.             nBottom = 1 ' Single Thin Line
  412.             
  413.         Case 2 ' Left
  414.             nLeft = 1 ' Single Thin Line
  415.             
  416.         Case 3 ' Right
  417.             nRight = 1 ' Single Thin Line
  418.             
  419.         Case 4 ' Double Thin Bottom
  420.             nBottom = 6 ' Double Thin Lines
  421.             
  422.         Case 5 ' Single Medium Bottom
  423.             nBottom = 2 ' Single Medium Line
  424.             
  425.         Case 6 ' Top/Bottom thin lines
  426.             nTop = 1 ' Single Thin Line
  427.             nBottom = 1 ' Single Thin Line
  428.             
  429.         Case 7 ' Top Thin, Bottom Double Thin
  430.             nTop = 1 ' Single Thin Line
  431.             nBottom = 6 ' Double Thin Lines
  432.         
  433.         Case 8 ' Top Thin, Bottom Medium
  434.             nTop = 1 ' Single Thin Line
  435.             nBottom = 2 ' Single Medium Line
  436.         
  437.         Case 9 ' Outline with separators
  438.             nTop = 1 ' Single Thin Line
  439.             nBottom = 1 ' Single Thin Line
  440.             nLeft = 1 ' Single Thin Line
  441.             nRight = 1 ' Single Thin Line
  442.         
  443.         Case 10 ' Outline Thin
  444.             nOutline = 1 ' Single Thin Line
  445.         
  446.         Case 11 ' Outline Medium
  447.             nOutline = 2 ' Single Medium Line
  448.         
  449.     End Select
  450.     
  451.     ' Set the new border
  452.     ss.SetBorder nOutline, nLeft, nRight, nTop, nBottom, nShade, crOutline, crLeft, crRight, crTop, crBottom
  453.     
  454.     ' Clean up
  455.     BorderForm.Hide
  456.     ss.SetFocus
  457.  
  458. End Sub
  459.  
  460. Sub SetObjectColor(ThePaletteEntry As Integer)
  461.  
  462.     Dim fColor As Long
  463.     Dim bColor As Long
  464.     Dim ThePattern As Integer
  465.     Dim TheRow As Integer, TheCol As Integer
  466.     Dim ObjectCount As Integer
  467.     Dim TheObjectCount As Integer
  468.     Dim TheObjectID As Long
  469.     Dim TheObjectType As Integer
  470.     Dim StartRow As Integer, EndRow As Integer, StartCol As Integer, EndCol As Integer
  471.     Dim ss As Object
  472.     
  473.     ' These are for the object descriptions
  474.     Dim TheStyle As Integer
  475.     Dim TheColor As Long
  476.     Dim TheWeight As Integer
  477.     
  478.     ' These are for the font description of a cell
  479.     Dim pFont As String
  480.     Dim pSize As Integer
  481.     Dim pBold As Boolean
  482.     Dim pItalic As Boolean
  483.     Dim pUnderline As Boolean
  484.     Dim pStrikeout As Boolean
  485.     Dim pcrColor As Long
  486.     Dim pOutline As Boolean
  487.     Dim pShadow As Boolean
  488.  
  489.     '' This procedure changes the foreground color of the currently selected
  490.     '' object.  The object may be the font color, or a drawing object like a
  491.     '' line or rectangle, or it may be the foreground of the cells in the
  492.     '' current selection.
  493.     
  494.     '' Multiple objects are handled, but multiple selections are not.  Therefore,
  495.     '' if there is more than one cell selection, only the current selection
  496.     '' will be changed.  Multiple selections can easily be added if you like.
  497.     
  498.     '' If the object we are operating on is a cell, there is a global flag
  499.     '' called 'TextOrFillColorFlag' that determines whether we are changing
  500.     '' the cell text color or the cell pattern color.
  501.  
  502.     ' If no active sheet then don't do anything
  503.     If Not (MainFrame.ActiveForm Is Nothing) Then
  504.         
  505.         ' Save the object into a variable to save on typing.
  506.         Set ss = MainFrame.ActiveForm.ss
  507.             
  508.         ' Turn off the Selection Change Event so we don't do all the
  509.         ' toolbar updating while formatting.
  510.         ss.DoSelChange = False
  511.         
  512.         '' This section handles the drawing objects.
  513.         
  514.         ' If there are no cell selections then see if there are object selections
  515.         If ss.SelectionCount = 0 Then
  516.             TheObjectCount = ss.ObjGetSelectionCount
  517.             If TheObjectCount > 0 Then
  518.                 For ObjectCount = 1 To TheObjectCount
  519.                     ss.ObjGetSelection ObjectCount - 1, TheObjectID
  520.                     TheObjectType = ss.ObjGetType(TheObjectID)
  521.                     
  522.                     ' If it's a line then change the line color
  523.                     If TheObjectType = F1ObjLine Then
  524.                         ss.GetLineStyle TheStyle, TheColor, TheWeight
  525.                         TheColor = ss.PaletteEntry(ThePaletteEntry)
  526.                         ss.SetLineStyle TheStyle, TheColor, TheWeight
  527.                     
  528.                     ' If it's a filled object, change the fill coloe
  529.                     ElseIf TheObjectType = F1ObjArc Or TheObjectType = F1ObjOval Or TheObjectType = F1ObjPolygon Or TheObjectType = F1ObjRectangle Then
  530.                         ss.GetPattern ThePattern, fColor, bColor
  531.                         fColor = ss.PaletteEntry(ThePaletteEntry)
  532.                         ss.SetPattern ThePattern, fColor, bColor
  533.                     End If
  534.                 
  535.                 Next ObjectCount
  536.             End If
  537.         
  538.         '' This section handles cell selections
  539.         
  540.         Else
  541.             ' Get the selection coordinates.  We have to look at each cell individually.
  542.             StartRow = ss.SelStartRow
  543.             EndRow = ss.SelEndRow
  544.             StartCol = ss.SelStartCol
  545.             EndCol = ss.SelEndCol
  546.     
  547.             ' Set the selection back to a single cell.
  548.             ss.SelStartRow = ss.Row
  549.             ss.SelStartCol = ss.Col
  550.             ss.SelEndRow = ss.Row
  551.             ss.SelEndCol = ss.Col
  552.     
  553.             ' Set the foreground color or text color of each cell.
  554.             ' If setting the fill color and the cell has no pattern
  555.             ' then set the pattern to 1 (solid).
  556.             For TheRow = StartRow To EndRow
  557.                 For TheCol = StartCol To EndCol
  558.                     ss.Row = TheRow
  559.                     ss.Col = TheCol
  560.                     If TextOrFillColorFlag = 0 Then '' Set Fill Color
  561.                         ss.GetPattern ThePattern, fColor, bColor
  562.                         ThePattern = IIf(ThePattern = 0, 1, ThePattern)
  563.                         fColor = ss.PaletteEntry(ThePaletteEntry)
  564.                         ss.SetPattern ThePattern, fColor, bColor
  565.                     Else '' Set Text Color
  566.                         ss.GetFont pFont, pSize, pBold, pItalic, pUnderline, pStrikeout, pcrColor, pOutline, pShadow
  567.                         pcrColor = ss.PaletteEntry(ThePaletteEntry)
  568.                         ss.SetFont pFont, -pSize, pBold, pItalic, pUnderline, pStrikeout, pcrColor, pOutline, pShadow
  569.                     End If
  570.                 Next TheCol
  571.             Next TheRow
  572.     
  573.             ' Restore selection
  574.             ss.SelStartRow = StartRow
  575.             ss.SelEndRow = EndRow
  576.             ss.SelStartCol = StartCol
  577.             ss.SelEndCol = EndCol
  578.             ss.Row = StartRow
  579.             ss.Col = StartCol
  580.         End If
  581.     
  582.     ss.DoSelChange = False
  583.     ss.SetFocus
  584.     
  585.     End If
  586.     
  587. End Sub
  588.  
  589. 'Sub ShowSSError(ByVal Er As Integer)
  590.    
  591. '   Dim ssError As String
  592. '
  593. '   If Er <> 0 And Er <> 20023 Then
  594. '      ssError = Space$(256)
  595. '      ssError = MainFrame.ActiveForm.ss.ErrorNumberToText(Er)
  596. '   End If
  597.  
  598. 'End Sub
  599.  
  600. Sub SSColorDlg(PosX As Long, PosY As Long)
  601.  
  602.     ' If there is a worksheet then load color form
  603.     If Not (MainFrame.ActiveForm Is Nothing) Then
  604.         Load ColorForm
  605.         ColorForm.Left = PosX
  606.         ColorForm.Top = PosY
  607.         ColorForm.Show
  608.     End If
  609.     
  610. End Sub
  611.  
  612. Function SSGetActiveHSS&()
  613.    SSGetActiveHSS& = MainFrame.ActiveForm.ss.ss
  614. End Function
  615.  
  616. Function SSGetActiveSS()
  617.    SSGetActiveSS = MainFrame.ActiveForm.ss
  618. End Function
  619.  
  620. Function SSIsActiveForm%()
  621.  
  622.    Dim bRet%
  623.    
  624.    bRet% = False
  625.    If Forms.Count > 1 Then
  626.       bRet% = True
  627.    End If
  628.    SSIsActiveForm% = bRet%
  629.  
  630. End Function
  631.  
  632. Sub SSMDIOpenFile(OptionalFileName As String)
  633.     
  634.    Dim FileName As String, FileType%
  635.    Dim Er As Integer
  636.  
  637.    FileName = Space$(256)
  638.    If Not SSIsActiveForm Then
  639.       Call C_New
  640.       If Not (MainFrame.ActiveForm Is Nothing) Then
  641.          MainFrame.ActiveForm.SetFocus
  642.       End If
  643.    End If
  644.    
  645.    On Error GoTo Cancel
  646.    
  647.    If OptionalFileName = "" Then
  648.       FileName = MainFrame.ActiveForm.ss.OpenFileDlgEx("Formula One Demo", MainFrame.hWnd)
  649.       Er = 0
  650.    Else
  651.       FileName = OptionalFileName
  652.       Er = 0
  653.    End If
  654.    
  655.    If Er <> 0 Then
  656.       'Call ShowSSError(Er)
  657.    Else
  658.       On Error GoTo CantCreateIt
  659.       Dim NewBook As New frmMDIChild
  660.       On Error GoTo UnloadIt
  661.  
  662.       FileType = NewBook.ss.ReadEx(FileName)
  663.       NewBook.ss.TableName = FileName
  664.       NewBook.Caption = FileName
  665.       NewBook.Visible = True
  666.       NewBook.ss.Tag = FileType
  667.       Exit Sub
  668.  
  669. Cancel:
  670.       If Err <> 20023 Then
  671.          'Call ShowSSError(Er)
  672.       End If
  673.       Exit Sub
  674.       
  675. CantCreateIt:
  676.       MsgBox "Unable to create " & FileName
  677.       Exit Sub
  678.  
  679. UnloadIt:
  680.       Unload NewBook
  681.       MsgBox "Unable to load " & FileName
  682.       
  683.       Exit Sub
  684.     End If
  685.  
  686. End Sub
  687.  
  688. Public Function SSMDISaveAsFile() As Long
  689.  
  690.    Dim Filespec As F1FileSpec
  691.    Dim Er As Integer
  692.    Dim FileType As Integer
  693.  
  694.    
  695.    On Error GoTo Cancel
  696.    MainFrame.ActiveForm.ss.SaveFileDlgEx "Formula One Demo", Filespec
  697.     
  698.    If Err <> 0 Then
  699.       'Call ShowSSError(Err)
  700.    Else
  701.       On Error GoTo CantWriteIt
  702.       MainFrame.ActiveForm.ss.WriteEx Filespec.Name, Filespec.Type
  703.       MainFrame.ActiveForm.ss.TableName = Filespec.Name
  704.       MainFrame.ActiveForm.Caption = Filespec.Name
  705.       MainFrame.ActiveForm.ss.Tag = Filespec.Type
  706.       SSMDISaveAsFile = 0
  707.       Exit Function
  708.  
  709. Cancel:
  710.     If Err <> 20023 Then
  711. '        Call ShowSSError(Er)
  712.     End If
  713.         SSMDISaveAsFile = vbCancel
  714.     Exit Function
  715.    
  716. CantWriteIt:
  717.       MsgBox "Unable to write " & Filespec.Name
  718.       Exit Function
  719.    End If
  720. End Function
  721.  
  722. Sub UpdateTextAndFillColors()
  723.  
  724.     Dim ss As Object
  725.  
  726.     '' This procedure keeps the colors updated on the toolbar
  727.     Set ss = MainFrame.ActiveForm.ss
  728.     'MainFrame.lblTextColor.BackColor = ss.PaletteEntry(CurrentTextColorIndex)
  729.     'MainFrame.lblFillColor.BackColor = ss.PaletteEntry(CurrentFillColorIndex)
  730.  
  731. End Sub
  732.  
  733. Public Sub UpdateAlignment()
  734.  
  735.     Dim WordWrap As Boolean, i As Integer
  736.    
  737.     For i = 8 To 11
  738.         MainFrame.tlbFormat.Buttons.Item(i).Value = tbrUnpressed
  739.     Next i
  740.     
  741.     Select Case MainFrame.ActiveForm.ss.HAlign
  742.        Case F1HAlignLeft
  743.           MainFrame.tlbFormat.Buttons.Item(8).Value = tbrPressed
  744.           
  745.        Case F1HAlignCenter
  746.           MainFrame.tlbFormat.Buttons.Item(9).Value = tbrPressed
  747.           
  748.        Case F1HAlignRight
  749.           MainFrame.tlbFormat.Buttons.Item(10).Value = tbrPressed
  750.           
  751.        Case F1HAlignCenterAcrossCells
  752.           MainFrame.tlbFormat.Buttons.Item(11).Value = tbrPressed
  753.           
  754.     End Select
  755.     
  756.     For i = 3 To 5
  757.         MainFrame.tlbFormat.Buttons.Item(i).Value = tbrUnpressed
  758.     Next i
  759.     
  760.     If MainFrame.ActiveForm.ss.FontBold Then MainFrame.tlbFormat.Buttons.Item(3).Value = tbrPressed
  761.     If MainFrame.ActiveForm.ss.FontItalic Then MainFrame.tlbFormat.Buttons.Item(4).Value = tbrPressed
  762.     If MainFrame.ActiveForm.ss.FontUnderline Then MainFrame.tlbFormat.Buttons.Item(5).Value = tbrPressed
  763.  
  764. End Sub
  765.  
  766. Public Sub UpdateCBOFontAndSize()
  767.  
  768.    Dim i%
  769.  
  770.     For i = 0 To Screen.FontCount - 1
  771.         
  772.         If StrComp(MainFrame.ActiveForm.ss.FontName, MainFrame.cboFontName.List(i), vbTextCompare) = 0 Then
  773.               MainFrame.cboFontName.ListIndex = i
  774.               MainFrame.cboFontSize.Text = Str(MainFrame.ActiveForm.ss.FontSize / 20)
  775.               Exit Sub
  776.         End If
  777.     Next i
  778.      
  779.     '' Empty selection since font not found
  780.     MainFrame.cboFontName.ListIndex = -1
  781.     MainFrame.cboFontSize.Text = ""
  782.    
  783. End Sub
  784.  
  785.  
  786.